package com.kaishengit.action;

import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;

import com.kaishengit.pojo.User;
import com.kaishengit.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

public class AppAction extends ActionSupport implements SessionAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Map<String,Object> session;
	private User user;
	private UserService userService;
	
	@Action("index")
	public String index() {
		return SUCCESS;
	}
	
	@Action(value="login",results={
			@Result(name=LOGIN,type="redirectAction",params={"actionName","index","code","10000"}),
			@Result(name=SUCCESS,type="redirectAction",params={"actionName","login","namespace","/user"})
	}
)
	public String login() {
		User u = userService.login(user);
		if(u!=null) {
			session.put("session_user", u);
			return SUCCESS;
		}else{
			return LOGIN;
		}
		
	}
	
	
	
	
	
	
	
	//get set
	public Map<String, Object> getSession() {
		return session;
	}
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public UserService getUserService() {
		return userService;
	}
	@Autowired
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	
	
}
